/**
 * Copyright (c) 2007-2008 Nearchos Paspallis
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
/**
 * AspectSense
 *
 * Middleware for annotation-based, context-aware and adaptive services for
 * mobile and ubiquitous computing
 *
 * This project is an open-source effort, initiated by Nearchos Paspallis as
 * part of his PhD work at the University of Cyprus (http://www.ucy.ac.cy).
 *
 * More information about the project is available at "http://aspectsense.org".
 */
package org.aspectsense.example_apps.digitalassistant;

import org.aspectsense.framework.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Set;
import java.util.HashSet;
import java.util.StringTokenizer;

/**
 * @author Nearchos Paspallis [nearchos@cs.ucy.ac.cy]
 *         Date: Feb 26, 2008
 *         Time: 5:42:26 PM
 */
public class Test
{
    public static void main(String[] args)
    {
        final String [] [] appointments = new String [] [] {
                {"Run code tests", "2/26/08 15:00", "2/26/08 16:00", "Lab 128, University of Cyprus, Nicosia", "Nearchos"},
                {"Coffee with Haris", "2/27/08 17:00", "2/27/08 18:00", "Starbucks central, Nicosia", "Nearchos, Haris"},
                {"Weekend by the beach", "2/29/08 15:00", "3/2/08 11:00", "Limassol", "Nearchos, Fani"},
        };

        // todo remove test
//        final UI ui = new VisualUI();
        final UI ui = new AudioUI();
        ((Component) ui).init();
        ((Component) ui).activate();

        final DateFormat dateFormat = new SimpleDateFormat("MM/dd/yy hh:mm");

        for(final String [] appointmentArray : appointments)
        {
            try
            {
                final String name = appointmentArray[0];
                final Date fromDate = dateFormat.parse(appointmentArray[1]);
                final Date toDate = dateFormat.parse(appointmentArray[2]);
                final String where = appointmentArray[3];
                final String participants = appointmentArray[4];
                final Set<String> participantsSet = new HashSet<String>();
                StringTokenizer stringTokenizer = new StringTokenizer(participants, ", ");
                final int numOfParticipants = stringTokenizer.countTokens();
                while(stringTokenizer.hasMoreTokens())
                {
                    participantsSet.add(stringTokenizer.nextToken());
                }
                final String [] participantsArray = participantsSet.toArray(new String [numOfParticipants]);
                final Appointment appointment = new Appointment(name, fromDate, toDate, where, participantsArray);

                ui.addedAppointment(appointment);
            }
            catch (ParseException pe)
            {
                pe.printStackTrace();
                System.exit(0);
            }
        }
        ui.communicateCompleteAgenda();
    }
}